﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using UIDesigner.DesignContainers.Bases;
using UIDesigner.Designers;
using UIDesigner.Editors;

namespace UIDesigner.SurfaceProperties
{
    public enum SurfaceDeletePropertyKind
    {
        DeleteOption,
        ConfirmOption,
        PostActions,
        DeleteState
    }

    public class SurfaceDeleteState : SurfaceStateBase
    {
        private SurfaceDeletePropertyKind m_eKind;
        private AFDesignerHost m_objHost;
        private IBaseObjectControl m_objControl;
        private SurfacePropertiesBase m_objSurrogateProperties;

        public SurfaceDeleteState(SurfaceDeletePropertyKind eKind, AFDesignerHost objHost, IBaseObjectControl objControl)
        {
            m_eKind = eKind;
            m_objHost = objHost;
            m_objControl = objControl;
        }

        public SurfaceDeleteState(SurfaceDeletePropertyKind eKind, AFDesignerHost objHost, IBaseObjectControl objControl, SurfacePropertiesBase objSurrogateProperties)
        {
            m_eKind = eKind;
            m_objHost = objHost;
            m_objControl = objControl;
            m_objSurrogateProperties = objSurrogateProperties;
        }

        public override IBaseObjectControl BaseObjectControl
        {
            get
            {
                return m_objControl;
            }
        }

        public override string Name
        {
            get
            {
                return "Surface Delete State Designer";
            }
        }

        public override string ToString()
        {
            return Enum.GetName(typeof(SurfaceDeletePropertyKind), m_eKind);
        }

        public override int Kind
        {
            get
            {
                return (int)m_eKind;
            }
        }

        public override AFDesignerHost Host
        {
            get
            {
                return m_objHost;
            }
        }

        public override Type KindType
        {
            get
            {
                return typeof(SurfaceDeletePropertyKind);
            }
        }
    }

    public class SurfaceDeleteDescriptor : PropertyDescriptor
    {
        private AFDesignerHost m_objHost;
        private SurfaceDeletePropertyKind m_eKind;
        private IBaseObjectControl m_objControl;
        private SurfacePropertiesBase m_objSurrogateProperties;

        public SurfaceDeleteDescriptor(AFDesignerHost objHost, IBaseObjectControl objControl, SurfaceDeletePropertyKind eKind, Attribute[] rgAttributes) : base(Enum.GetName(typeof(SurfaceDeletePropertyKind), eKind), rgAttributes)
		{
            m_objHost = objHost;
            m_eKind = eKind;
            m_objControl = objControl;
        }

        public SurfaceDeleteDescriptor(AFDesignerHost objHost, IBaseObjectControl objControl, SurfaceDeletePropertyKind eKind, Attribute[] rgAttributes, SurfacePropertiesBase objSurrogateProperties) : base(Enum.GetName(typeof(SurfaceDeletePropertyKind), eKind), rgAttributes)
		{
            m_objHost = objHost;
            m_eKind = eKind;
            m_objControl = objControl;
            m_objSurrogateProperties = objSurrogateProperties;
        }

        private SurfacePropertiesBase SurfaceProperties
        {
            get
            {
                if (m_objSurrogateProperties == null)
                {
                    return m_objHost.SurfacePropertiesSet[m_objControl];
                }
                else
                {
                    return m_objSurrogateProperties;
                }
            }
        }

		public override bool CanResetValue(object component)
		{
			return true;
		}

		public override Type ComponentType
		{
			get 
            {
                return m_objHost.RootComponent.GetType(); 
            }
		}

		public override object GetValue(object component)
		{
            switch (m_eKind)
            {
                case SurfaceDeletePropertyKind.DeleteOption:
                    return new DynamicEnumType(m_objHost, m_objControl, typeof(DeleteOptions), (int)this.SurfaceProperties.DeleteProperties.DeleteOptions);
                case SurfaceDeletePropertyKind.ConfirmOption:
                    return this.SurfaceProperties.DeleteProperties.DeleteConfirmOptions;
                case SurfaceDeletePropertyKind.PostActions:
                    return this.SurfaceProperties.DeleteProperties.PostActions;
                case SurfaceDeletePropertyKind.DeleteState:
                    return new SurfaceDeleteState(m_eKind, m_objHost, m_objControl, m_objSurrogateProperties);  
                default:
                    Debugger.Break();
                    return null;
            }
		}

		public override bool IsReadOnly
		{
			get 
            {
                return false; 
            }
		}

		public override Type PropertyType
		{
			get 
            {
                switch (m_eKind)
                {
                    case SurfaceDeletePropertyKind.DeleteOption:
                        return typeof(DynamicEnumType);
                    case SurfaceDeletePropertyKind.ConfirmOption:
                        return typeof(ConfirmOptions);
                    case SurfaceDeletePropertyKind.PostActions:
                        return typeof(PostActions);
                    case SurfaceDeletePropertyKind.DeleteState:
                        return typeof(SurfaceDeleteState);
                    default:
                        Debugger.Break();
                        return null;
                }
            }
		}

		public override void ResetValue(object component)
		{
			
		}

		public override void SetValue(object component, object value)
		{
            if (value == null)
            {
                return;
            }

            switch (m_eKind)
            {
                case SurfaceDeletePropertyKind.DeleteOption:
                    this.SurfaceProperties.DeleteProperties.DeleteOptions = (DeleteOptions)value;
                    break;
                case SurfaceDeletePropertyKind.ConfirmOption:
                    this.SurfaceProperties.DeleteProperties.DeleteConfirmOptions = (ConfirmOptions)value; 
                    break;
                case SurfaceDeletePropertyKind.PostActions:
                    this.SurfaceProperties.DeleteProperties.PostActions = (PostActions)value;
                    break;
                case SurfaceDeletePropertyKind.DeleteState:
                    break;
                default:
                    Debugger.Break();
                    break;
            }
        }

		public override bool ShouldSerializeValue(object component)
		{
			return false;
		}

		public override string Category
		{
			get
			{
				return "Surface Properties";
			}
		}

		public override string Description
		{
			get
			{
				return "Shows the hidden field names\r\nAlthough these properties exists at the selected object's type you cannot see them as editable";
			}
		}
    }
}
